<?php
/**
 * tool.class - tools
 * alias to _.class
 *
 * @version:	0.1a
 * @package:	global
 * @author:		alex_ez
 * @created:	16.02.2009 15:02:27
 *
 * @copyright:	(c) 2009 alex <qfox@ya.ru> yaroshevich aka alex_ez. All rights reserved.
 */


final class tool
{
	static public function __callStatic( $m, $p )
	{
		if( is_callable( array( '_', $m ) ) )
			return call_user_func_array( "_::$m", $p );
		
		if( is_callable( array( '_a', $m ) ) )
			return call_user_func_array( "_a::$m", $p );

		throw new Exception( 'Method "' . $m . '" of class "' . __CLASS__ . '" does not exists' );
	}

	static public function subst($pattern, $fields, $wrapper = ':%s')
	{
		return _::subst($pattern, $fields, $wrapper);
	}
	static public function parse_args($args, $defaults = false) {
		return _::parse_args($args, $defaults);
	}
	static public function extract_args($args, $defaults) {
		return _::extract_args($args, $defaults);
	}
	static public function pluraltext_ru( $n, $s = 'm', $st = null ) {
		return _::pluraltext_ru( $n, $s, $st );
	}
	static public function replace_pattern($str, $vars) {
		return _::replace_pattern($str, $vars);
	}


	static public function mb_ucfirst($string) {
        return mb_strtoupper(mb_substr($string, 0, 1)) . mb_substr($string, 1);
    }



	static public function flat( $A, $tkey, $tvalue = null ) {
		return _a::flat( $A, $tkey, $tvalue );
	}
	static public function joinf( $d = null, $a, $t = null ) {
		return _a::joinf( $d, $a, $t );
	}
	static public function simplify( $A, $backlevel = 0 ) {
		return _a::simplify( $A, $backlevel );
	}
	static public function transpose($array) {
		return _a::transpose($array);
	}
	static public function remap($A, $map, $strict = false) {
		return _a::remap($A, $map, $strict);
	}

	static public function unset_keys($A, $keys) {
		return _a::unset_keys($A, $keys);
	}


	static public function pick( )
	{
		$_A = func_get_args();
		if( sizeof( $_A ) == 1 && is_array( reset( $_A ) ) ) $_A = reset( $_A );
		
		foreach( array_keys( $_A ) as $k )
		if( isset( $_A[$k] )
		 && !is_null( $_A[$k] ) )
			return $_A[$k];
		
		return null;
	}
	
	static public function pick_any( )
	{
		$_A = func_get_args();
		if( sizeof( $_A ) < 1 ) return null;
		
		return $_A[ rand( 0, sizeof( $_A )-1 ) ];
	}

}


